package com.explorati.design_pattern.creational.prototype.clone.example;

import java.util.Date;

public class ClientDemo {

	private static int MAX_COUNT = 6;

	public static void main(String[] args) throws CloneNotSupportedException {
		int i = 0;
		Mail mail = new Mail("某商场五一抽象活动", "五一抽象活动通知：凡在五一期间在本商场购物满100元的客户都有获得抽奖机会！");
		mail.setDate(new Date(66666666L));

		mail.setTail("解释权归某商场所有");

		while (i < 1) {
			System.out.println(mail.getDate());
			Mail cloneMail = (Mail) mail.clone();
			cloneMail.setApplellation(MailUtils.getRandString(5) + "先生(女士)");
			cloneMail.setReceiver(MailUtils.getRandString(5) + "@" + MailUtils.getRandString(8) + ".com");
			/**
			 * 深克隆和浅克隆的对比
			 * 深克隆：当原先mail的date改变时，clone的clonemail不会变
			 * 浅克隆：当原先的mail的date改变时，clonemail的date也改变
			 */
			MailUtils.sendMail(cloneMail, mail.getDate());
			mail.getDate().setTime(222222L);
			System.out.println(mail.getDate());
			MailUtils.sendMail(cloneMail, mail.getDate());
			i++;
		}
	}
}
